var taskId = null;

$(document).ready(function() {

	var date = new Date();
	date.setTime(date.getTime() + (1 * 24 * 60 * 60 * 1000));
	// 设置tasktree的样式
	$("#navigation").treeview({
				animated : "fast",
				control : "#contreecontrol1",
				persist : "location",
				collapsed : false
			});

	//事件详情
	$(".eventDetail").click(function() {
				var eid = $.cookie('taskEventId');
				redirectPage("/ag/wzp/event_findById.action?event.EId="
						+ $.trim(eid));
			});
    //任务详情
	$(".taskDetail").click(function() {
		        $.cookie('tasktrackid',null);
				$.cookie('tasktrackid', $(this).attr("value"), { path: '/', expires: date });
				redirectPage("/ag/lzw/task_detail.jsp");
			});
	//任务反馈
	$(".taskfeedback").click(function() {
		        $.cookie('tasktrackid',null);
				$.cookie('tasktrackid', $(this).attr("value"), { path: '/', expires: date });
				redirectPage("/ag/lzw/tracklist_trackdetail_main.jsp");
			});
    //新增任务
	$("#bt_addtask").click(function() {
		        $.cookie('tasktrackid', $(".newtask").attr("value"));
				redirectPage("/ag/lzw/addtask.jsp");
			});
    //添加任务反馈
	$("#bt_addfeeback").click(function() {
		        redirectPage("/ag/lzw/handelFeedback_addFeedback.action?toid="+$(".addtaskfeedback").attr("value"));
			});

	$(".taskOver").click(function() {
		taskId = $(this).attr("value");
		$.ajax({
					type : "post",
					url : "lzw/TaskOver_isLeader.action?tid="+$(this).attr("value"),         //判断该用户是否为指挥长
					dataType : "JSON",
					success : function(data){
				    var data = eval("(" + data + ")");
//				    alert(data.leader);
				    if(data.leader=="1"){
		              $.cookie('zhhtaskid',null);
		              $.cookie('zhhtaskid', taskId, { path: '/', expires: date });
//			          $.cookie('zhhtaskid', $(this).attr("name"), { path: '/', expires: date });
//			          $('#tabFrame', window.parent.document).attr("src", "/ag/zhh/taskOver_request_main.jsp");
			          redirectPage("/ag/zhh/taskOver_request_main.jsp");
		             }else{
			           $.cookie('tasktrackid',null);
			           $.cookie('tasktrackid', taskId, { path: '/', expires: date });
//			           $.cookie('tasktrackid', $(this).attr("name"), { path: '/', expires: date });
//			           $('#tabFrame', window.parent.document).attr("src", "/ag/lzw/taskOver_request_main.jsp");
			           redirectPage("/ag/lzw/taskOver_request_main.jsp");
			          }
					},
					error : function(textStatus) {					
						return false;
					}
				});
			});

	function redirectPage(url) {
		$('#taskTrackFrame', window.parent.document).attr("src", url);
	}
});
